/**
 * Created by hansin on 2017/8/26.
 */
import React, {
    Component
} from 'react'
import {
    connect
} from 'react-redux';
import LazyLoad from 'react-lazyload'
import PlaceholderComponent from '../../Placeholder'
import {getCookie} from '../../../static/js/global'

import Row from 'antd/lib/row';
import Col from 'antd/lib/col';
//import Button from 'antd/lib/button';
import Affix from 'antd/lib/affix';



class MFollowPage extends Component {
    state = {
        top: 0,
        show: false,
        couponId: null
    }

    handleFollow = () =>{
        let shopId = getCookie('shopId');
        let url = `http://www.onloon.net/landing/pc_CouponPage.html?shopId=${shopId}&id=${this.state.couponId}`;
        window.open(url, '', '')
    }

    componentDidMount(){
        this.props.getFollowInfo()
        .then((res)=>{
            if (res && res.data && res.data.success && res.data.data) {
                this.setState({
                    show: true,
                    couponId: res.data.data
                })
            }
        })

        if(document){
            //rem转px
            let html = document.getElementsByTagName('html')[0];
            let fontSize = parseInt(html.style["font-size"])
            let width = fontSize*1.333333
            this.setState({
                top: width
            })
        }

    }

    render() {
        const btnStyle = {
            top: "30%",
            right: "4%",
            backgroundColor: "transparent",
            borderColor: "transparent",
            color: '#333',
            width: 100,
            height: 50,
        }

        //判断是否设置了加粉助手，如果未设置，返回null
        if (this.state.show) {
            return (
                <div onClick={this.handleFollow}>
                    <LazyLoad offset={[-200, 0]} placeholder={<PlaceholderComponent />} >
                        <img style={{width: '100%'}} src='../../../static/img/followus-mobile.png'/>
                    </LazyLoad>
                </div>
            )
        } else {
            return null
        }

    }
}

export default MFollowPage